package com.yx.controller;
import com.yx.annotation.SystemLog;
import com.yx.domain.ResponseResult;
import com.yx.domain.dto.TagListDto;
import com.yx.domain.entity.Tag;
import com.yx.domain.vo.PageVo;
import com.yx.domain.vo.TagVo;
import com.yx.enums.AppHttpCodeEnum;
import com.yx.exception.SystemException;
import com.yx.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @author 86159
 */
@RestController
@RequestMapping("/content/tag")
public class TagController {
    @Autowired
    private TagService tagservice;
    @GetMapping("/list")
    @SystemLog(businessName = "内容管理->标签管理->标签名搜索")
    public ResponseResult<PageVo> list(Integer pageNum, Integer pageSize, TagListDto tagListDto){
        return tagservice.pageTagList(pageNum,pageSize,tagListDto);

    }
    @PostMapping
    @SystemLog(businessName = "内容管理->标签管理->添加标签")
    public ResponseResult addTag(@RequestBody Tag tag){
        if(!StringUtils.hasText(tag.getName())){
            throw new SystemException(AppHttpCodeEnum.TAG_IS_NULL);
        }
        return tagservice.addTag(tag);
    }
    @DeleteMapping("{id}")
    @SystemLog(businessName = "内容管理->标签管理->删除标签")
    public ResponseResult deleteTag(@PathVariable("id") Long id){
        return tagservice.deleteTag(id);
    }
    @GetMapping("{id}")
    @SystemLog(businessName = "内容管理->标签管理->查询标签信息")
    public ResponseResult getTagInfo(@PathVariable("id") Long id){
        return tagservice.getTagInfo(id);
    }
    @PutMapping
    @SystemLog(businessName = "内容管理->标签管理->修改标签")
    public ResponseResult updateTag(@RequestBody Tag tag){
        return tagservice.updateTag(tag);
    }
}
